

var userDB = require('../db/userDB');



//.- Recibimos el servidor creado por express y manejamos los servicios REST para el usuario
module.exports = function(app){

	//.- Login
	login = function(req,res){
		//var usuario = {user:req.query.user,password:req.query.password};
		//.- usamos req.query para GET (usar req.body para POST)
		var usuario = {user:req.query.user,password:req.query.password};
		userDB.login(usuario,function(data){
			res.json(data);			
		});	
	};	
	
	register = function(req,res){
		//var _user = JSON.parse(req.body);	
		
		//var _user = eval('('+req.body.user+')');
		var _user = {user:'dyanez',password:'admin'};
		
		_user["registerDate"] = new Date();
		
		//var _date = new Date();
		
		userDB.register(_user,function(data){
			if(data.success)
				res.json({success:true,msg:"Ud ha sido registrado exitosamente",user:data.user});
			else
				res.json({success:false,msg:"Error al registrar. Por favor intentar m�s tarde"});
		});
		
		//.- guardar imagen base64 en disco
		
		//http://stackoverflow.com/questions/5669541/node-js-how-to-save-base64-encoded-images-on-server-as-png-jpg
		//http://stackoverflow.com/questions/5867534/how-to-save-canvas-data-to-file
		//http://stackoverflow.com/questions/15772394/how-to-upload-display-and-save-images-using-node-js-and-express
		
		//resize imga:http://stackoverflow.com/questions/11599357/resizing-images-with-nodejs-and-imagemagick
		//http://stackoverflow.com/questions/6926016/nodejs-saving-a-base64-encoded-image-to-disk
		
		//NOTIFICATION--> http://devgirl.org/2012/10/25/tutorial-android-push-notifications-with-phonegap/
		
		
	};
	
	getUserTest = function(req,res){
		//var usuario = {user:req.query.user,password:req.query.password};
		//.- usamos req.query para GET (usar req.body para POST)
		var usuario = {user:'dyanez'};
		userDB.getUserTest(usuario,function(data){
			res.json(data);			
		});	
	};
	
	registerTest = function(req,res){
		//var _user = JSON.parse(req.body);	
		
		//var _user = eval('('+req.body.user+')');
		var _user = {user:'dyanez',password:'admin'};
		
		_user["registerDate"] = new Date();
		
		//var _date = new Date();
		
		userDB.register(_user,function(data){
			if(data.success)
				res.json({success:true,msg:"Ud ha sido registrado exitosamente",user:data.user});
			else
				res.json({success:false,msg:"Error al registrar. Por favor intentar m�s tarde"});
		});
		
		//.- guardar imagen base64 en disco
		
		//http://stackoverflow.com/questions/5669541/node-js-how-to-save-base64-encoded-images-on-server-as-png-jpg
		//http://stackoverflow.com/questions/5867534/how-to-save-canvas-data-to-file
		//http://stackoverflow.com/questions/15772394/how-to-upload-display-and-save-images-using-node-js-and-express
		
		//resize imga:http://stackoverflow.com/questions/11599357/resizing-images-with-nodejs-and-imagemagick
		//http://stackoverflow.com/questions/6926016/nodejs-saving-a-base64-encoded-image-to-disk
		
		//NOTIFICATION--> http://devgirl.org/2012/10/25/tutorial-android-push-notifications-with-phonegap/
		
		
	};
	
	recoveryPassword = function(req,res){
		var email = require();
	};
	
	
	
	//Servicios REST para usuario
	app.get("/login",login);
	app.get("/getUserTest",getUserTest);	
	app.post("/register",register);
	app.get("/registerTest",registerTest);
	app.get("/recoveryPassword",recoveryPassword);
};
